package com.zr.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.CarDao;
import com.zr.model.TCar;
import com.zr.model.TCarstate;
import com.zr.service.CarService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 重写车辆的service层编写具体实现
 * @author Administrator
 *
 */
//把这个类当做一个service层
@Service("carService")
public class CarServiceImpl implements CarService {
	//按照配置（依据名称或者依据类型）给属性注入实例
	@Resource
	private  CarDao<TCar>  carDao;
	@Override
	public JSONObject showCarMsg(int page, int rows) {
		// TODO Auto-generated method stub
		//Map<String,Object> obj = new HashMap<String,Object>();
		JSONObject obj = new JSONObject();
		obj.put("total", carDao.showCarCount());
		obj.put("rows", carDao.showCarMsg(page, rows));
		//JSONObject jso = JSONObject.fromObject(obj);
		return obj;
	}
	@Override
	public JSONArray findCarCsnameMsg() {
		// TODO Auto-generated method stub
		return carDao.findCarCsnameMsg();
	}
	@Override
	public boolean addCarMsg(String cname, String cvolume, int csid) {
		// TODO Auto-generated method stub
		return carDao.addCarMsg(cname, cvolume,carDao.findTCarstateCsid(csid));
	}
	@Override
	public void deleteCarMsg(String[] cids) {
		// TODO Auto-generated method stub
		for (int i = 0; i < cids.length; i++) {
			carDao.deleteCarMsg(Integer.valueOf(cids[i]));
		}
	}
	@Override
	public void updateCarMsg(int cid, String cname, String cvolume, int csid) {
		// TODO Auto-generated method stub
		carDao.updateCarMsg(cid, cname, cvolume, carDao.findTCarstateCsid(csid));
	}
}
